package com.cdream.basic.thread;

import java.util.concurrent.LinkedTransferQueue;
import java.util.concurrent.TransferQueue;

/**
 * @author cdream
 * @date 2021/9/9
 */
public class TransferQueueExample {
    public static void main(String[] args) {
        TransferQueue<Character> t = new LinkedTransferQueue<>();
        char[] char1 = "123456".toCharArray();
        char[] char2 = "abcdef".toCharArray();
        new Thread(()-> {
            for (char c : char1) {
                try {
                    t.transfer(c);
                    System.out.println(t.take());
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();
        new Thread(()-> {
            for (char c : char2) {
                try {
                    System.out.println(t.take());
                    t.transfer(c);
                } catch (InterruptedException e) {
                }

            }
        }).start();

    }
}
